package com.gui.service;

import com.gui.DTO.QuestionDTO;
import com.gui.mapper.QuestionMapper;
import com.gui.mapper.UserMapper;
import com.gui.model.Question;
import com.gui.model.User;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.LinkedList;
import java.util.List;

/**
 * MainVeiwService
 *
 * @author guigu
 * @QQ 1170258867
 * @date 2020/5/30
 * @description
 */
@Service
public class MainVeiwService {

    @Autowired
    private QuestionMapper questionMapper;
    @Autowired
    private UserMapper usermapper;

    public List<QuestionDTO> getQuestionDTO(){
        List<Question> allQuestion = questionMapper.getAllQuestion();
        List<QuestionDTO> questionDTOS = new LinkedList<>();
        for (Question question : allQuestion) {
            User user = usermapper.selectById(question.getCreator());
            QuestionDTO questionDTO = new QuestionDTO();
            BeanUtils.copyProperties(question,questionDTO);
            questionDTO.setUser(user);
            questionDTOS.add(questionDTO);
        }
        return questionDTOS;
    }

}
